package com.example.markingsystem.controller;

import com.example.markingsystem.bean.graduateinfo;
import com.example.markingsystem.bean.openidrecord;
import com.example.markingsystem.mapper.GraduateinfoMapper;
import com.example.markingsystem.mapper.LoginMapper;
import com.example.markingsystem.service.GraduateinfoService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class GraduateinfoController {
    @Resource
    private GraduateinfoMapper graduateinfoMapper;

    @Resource
    private LoginMapper loginMapper;
    @RequestMapping("addGraduateInfo")
    public String addGraduateInfo(@Param("name") String name , @Param("studentid") String studentid , @Param("isfirst") int isfirst, @Param("telephone") String telephone, @Param("region") String region, HttpSession session){
        graduateinfo g = new graduateinfo();
        String nowuseridcode = (String) session.getAttribute("userlogin");
        g.setIdcode(nowuseridcode);
        g.setName(name);
        g.setStudentid(studentid);
        g.setIsfirst(isfirst);
        g.setTelephone(region+telephone);
        graduateinfoMapper.addInfo(g);

        String nowopenid = (String) session.getAttribute("nowopenid");
        openidrecord nowrecord = new openidrecord();
        nowrecord.setIdcode(nowuseridcode);
        nowrecord.setOpenid(nowopenid);
        loginMapper.insertOpenidRecord(nowrecord);


        return "test";
    }

    @RequestMapping("toAddGraduateInfo")
    public String toAddGraduateInfo(){
        return "yanjiushengInfo";
    }
}
